package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Author: 周训发
 * @CreateTime: 2025-10-22
 * @Description: 利用AOP实现统计每个请求方法的耗时
 * @Version: 1.0
 */

@Component
@Aspect
@Slf4j
public class TimeAspect {

//    @Around("execution(* com.itheima.service.*.*(..))")
    public Object recodeAspect(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        long begin = System.currentTimeMillis();
        //调用原始操作----公共部分的代码执行
        Object proceed = proceedingJoinPoint.proceed();
        long end = System.currentTimeMillis();
        log.info(proceedingJoinPoint.getSignature()+"{}ms",end-begin);
        return proceed;
    }
}
